<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表单验证</title>
</head>
<body>
    <form action="http://baidu.com" target="_blank">
        <div class="form-group">
            <input type="text" name="username">
        </div>
        <div class="form-group">
            <input type="password" name="password">
        </div>
        <div class="form-group">
            <input type="submit" value="注册" id="submit">
        </div>
    </form>
    <script src="./js/validate-form.js"></script>
    <script>
        const formOption = {
            formSelector:'form',
            submitSelector:'#submit',
            fieldsOpt:{
                username:{
                    selector:"input[name=username]",
                    rules:{
                        value:/\w{3,}/
                    },
                    errorMsg: "没有账号吗"
                }
            },
            fieldCallback(isPass,field, msg, element){

            },
            formCallback: function (isPass,valiRes){
                console.log('表单验证失败')
                alert('表单验证失败')
            }
        }
        new ValidateForm(formOption)
    </script>
</body>
</html>